package com.nlgc365.designpattern.Chapter04_Pattern.Creation.P02_Factory.Calculator;

import java.util.Scanner;

/**
 * Calculator Console Program
 * Enter two numbers and operation symbols,then get the result.
 */
public class Calculator_v2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            // input two number
            System.out.println("Input num1: ");
            int num1 = scanner.nextInt();
            System.out.println("Input num2: ");
            int num2 = scanner.nextInt();

            // input symbol
            System.out.println("Input Symbol: ");
            String symbol = scanner.next();
            calculate(num1, num2, symbol);
        }
    }

    private static int calculate(int num1, int num2, String symbol) {
        // Perform calculations and output the result in console
        int result = 0;
        switch (symbol) {
            case "+":
                result = num1 + num2;
                break;
            case "-":
                result = num1 - num2;
                break;
            case "*":
                result = num1 * num2;
                break;
            case "/":
                result = num1 / num2;
                break;
            case "%":
                result = num1 % num2;
                break;
            default:
                System.out.println("Feature not supported");
                break;
        }
        return result;
    }
}
